app.controller("workload",function($scope,$uibModal,$rootScope,del,$state,get,$stateParams ){
		get.list("taskP/count",{}).then(function(e){
				$scope.dwc=e.dwc
				$scope.ywc=e.ywc
				
			})
		$scope.search=function(i,tState){
			$scope.tState=tState||0
			var param={
			pageNum:i||'1',
			pageSize:6,
			tState:$scope.tState||0
		}
			
	get.list("taskP/count",{}).then(function(e){
				$scope.dwc=e.dwc
				$scope.ywc=e.ywc
				
			})

		get.list("taskP/all",param).then(function(e){
				$scope.list=e.list
				$scope.pageSize = e.pageSize; //每页多少条
				$scope.totalNum = e.pageCount; //总共多少页
				$scope.totalSize =e.totalNums; //总共多少条   
				$scope.pageNum = e.pageNum; //当前页面
			})
		}
		$scope.search();
		$scope.pageUp=function(){//跳转页码
       	if ($scope.tj.page>$scope.totalNum) {
       		$scope.tj.page=$scope.totalNum
       	} else if($scope.tj.page<1){
       	$scope.tj.page=null
       	}
       }//pageUp
   $scope.toPage=function(i){//点击跳转
       i=i||$scope.tj.page
       	$scope.search(i)
       	$scope.tj.current=$scope.tj.page;//页码调整
   }//toPage
   if($stateParams.page!=null){
			$scope.tj={
				page:$stateParams.page
			}
		 $scope.toPage($stateParams.page)
	}else{
			$scope.search();
	}
/**
	 * 详情
	 * @param {Object} id
	 * @param {Object} tab
	 */
	$scope.columnXQ = function(id,tab) {
		$uibModal.open({ //模态框
			animation: true,
			templateUrl: 'workXQ.html',
			size: 'lg',
			 backdrop: 'static' ,
			controller: 'workXQ',
			resolve: { //这是一个入参,这个很重要,它可以把主控制器中的参数传到模态框控制器中
				id: function() { //是一个回调函数
					return id; //这个值会被模态框的控制器获取到
				},
				tab:function (){
					return tab;
				},
				current:function (){
					return $scope.current;
				},
				pageNum:function (){
					return $scope.pageNum;
				},
				scope:function(){
					return $scope;
				}
			}
		}) //模态框
	}
	
	/**
	 * 增加与修改
	 * @param {Object} id
	 * @param {Object} tab
	 */
	$scope.columnAdd = function(id,tab) {
		$uibModal.open({ //模态框
			animation: true,
			templateUrl: 'workAdds.html',
			size: 'lg',
			 backdrop: 'static' ,
			controller: 'workAdds',
			resolve: { //这是一个入参,这个很重要,它可以把主控制器中的参数传到模态框控制器中
				id: function() { //是一个回调函数
					return id; //这个值会被模态框的控制器获取到
				},
				tab:function (){
					return tab;
				},
				current:function (){
					return $scope.current;
				},
				pageNum:function (){
					return $scope.pageNum;
				},
				scope:function(){
					return $scope;
				}
			}
		}) //模态框
	}
	
})
app.controller('workXQ',function($scope,$rootScope,get,pageNum,ngTreetableParams,$uibModalInstance,tab,id,$http,post,pos,scope,$state,current,Upload){
	$scope.id=id
	$scope.current=current
	$scope.param=[]
	$scope.param.taskImageList=[];
	$scope.iss=true
	if(tab=='add'){
		$scope.iss=false
	}
	get.list("task/selectBytId",{tId:$scope.id}).then(function(e){
			$scope.param=e
			$scope.pickertime=e.tStartTime
			$scope.pickertimes=e.tEndTime
			console.log($scope.param)
		})
	$scope.imgYl=function(val){
		window.open(val)
	}
	$scope.cancel = function() {
		$uibModalInstance.close();
	};
	$scope.ok=function(){
			post.list("task/updateByStatus",{tId:$scope.id}).then(function(e){
				console.log(e)
				$uibModalInstance.close();
				$rootScope.open(e);
				scope.search(pageNum)
			});	
	}
	
});

app.controller('workAdds',function($scope,$rootScope,get,pageNum,ngTreetableParams,del,$uibModalInstance,tab,id,$http,post,pos,scope,$state,current,Upload){
	$scope.id=id
	$scope.current=current
	$scope.param=[]
	$scope.param.taskImageList=[]
	$scope.files=[]
	//项目名称
	$scope.imgYl=function(val){
		window.open(val)
	}
	$scope.delimg=function(val,list){
		$scope.param.taskImageList.splice($.inArray(id, $scope.param.taskImageList), 1);
		del.list("task/deletefile",{url:val}).then(function(e){
			console.log(e)
		});	
	}
	  $scope.submit = function () {
                $scope.upload($scope.file);
                console.log($scope.file)
                
            };
            $scope.upload = function (file) {
                $scope.fileInfo = file;
                angular.forEach(file,function(files){
                	Upload.upload({
                	 method:'POST',
                    //服务端接收
                    url: localStorage.getItem("Url")+'task/uploadfile',
                    //上传的同时带的参数
                    data: {file:files}
                }).progress(function (evt) {
                	
                    //进度条
                    //var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
                    //console.log(  evt.config);
                }).success(function (data, status, headers, config) {
                		$scope.files.push(files)
                		$scope.param.taskImageList.push(data.data[0])
                	
                    //上传成功
                    console.log($scope.param.taskImageList);
                }).error(function (data, status, headers, config) {
                    //上传失败
                    $rootScope.open(data.data);
                });

                })
                	
                
            };
	
	get.list("dictionary/project").then(function(e){
		$scope.typeDic=e
		$scope.typeDic.unshift({
				diName:"请选择",
				diId:''
			})
	})
	if(tab=='add'){
		$scope.param.tProId=''
		$scope.param.tDesigneeId=''
		$scope.sername="添加";
	}
	if($scope.id==0||$scope.href==''){
		$scope.type="menu"
	}else{
		$scope.type="permission"
	}
	$scope.ok=function (){
		
		if(tab=='add'){
			console.log($scope.param)
			$scope.param.tStartTime=$scope.pickertime
			$scope.param.tEndTime=$scope.pickertimes
			angular.forEach($scope.typeDic,function(val){
				if(val.diId==$scope.param.tProId){
					$scope.param.tProName=val.diName
				}
			})
			var par=$scope.param
			console.log(par)
			var pars={
				"taskImageList":$scope.param.taskImageList,
				"tProId":$scope.param.tProId,
				"tName":$scope.param.tName,
				"tType":$scope.param.tType,
				"tWorkload":$scope.param.tWorkload,
				"tStartTime":$scope.param.tStartTime,
				"tEndTime":$scope.param.tEndTime,
				"tProName":$scope.param.tProName,
				"tDetail":$scope.param.tDetail
			}
			post.list("task/saveByOwn",{task:JSON.stringify(pars)}).then(function(e){
				$uibModalInstance.close();
				$rootScope.open(e);
				scope.search(pageNum)
			});
		}
	}
	$scope.cancel = function() {
		$uibModalInstance.close();
	};
	
});
